<?php
/*
 * Formfield model for retrieving asset form field
 */

class Asset_Model_Formfield extends WOW_Model_Acl_Abstract
{
    public function getResourceId()
    {
        return 'Formfield';
    }

    public function getFormFieldsById($id)
    {
        $id = (int) $id;
        $temp_fields = $this->getResource('Formfield')->getFormFieldsById($id);
        $fields_details = $temp_fields->toArray();
        return $fields_details;
    }

    public function getAllFormFields()
    {
         return $this->getResource('Formfield')->getAllFormFields();
    }
    
    public function getAllFormFieldsArray()
    {
        $all_fields  = $this->getResource('Formfield')->getAllFormFields();

        $ret_ar = array();
        foreach($all_fields as $field)
        {
            $ret_ar[$field->id] = array(
                                        'catid'     => $field->catid,
                                        'subcatid'  => $field->subcatid,
                                        'labelid'   => $field->AssetCatLabelId,
                                        'field_name'=> $field->FieldName,
                                        'is_required'=> $field->isRequired,
                                        'input_validation'=>$field->InputValidation,
                                        'length'    => $field->Length,
                                        'input_type' => $field->InputType
                                        );
        }

        return $ret_ar;
    }


    public function getFormFieldByCategorySubcategoryLabel($catid, $subcat_id, $labelid)
    {
        $flds = $this->getResource('Formfield')->getFormFieldByCategorySubcategoryLabel($catid, $subcat_id, $labelid);

        $ret_ar = array();
        foreach($flds as $field)
        {
            $ret_ar[$field->id] = array(
                                        'catid'     => $field->catid,
                                        'subcatid'  => $field->subcatid,
                                        'labelid'   => $field->AssetCatLabelId,
                                        'field_name'=> $field->FieldName,
                                        'is_required'=> $field->isRequired,
                                        'input_validation'=>$field->InputValidation,
                                        'length'    => $field->Length,
                                        'input_type' => $field->InputType
                                        );
        }

        return $ret_ar;
    }


    #@ TODO:: needs to be worked on ACL later
    public function setAcl(WOW_Acl_Interface $acl)
    {
        if (!$acl->has($this->getResourceId()))
        {
            $acl->add($this)->allow('Normal', $this, array('register'))
            ->allow('Moderator', $this, array('saveCategory'))
                    ->allow('Admin', $this);
        }
        $this->_acl = $acl;
        return $this;
    }

    public function getAcl()
    {
        if (null === $this->_acl) {
            $this->setAcl(new Main_Model_Acl_Main());
        }
        return $this->_acl;
    }
}

?>
